package stu.day9_day18;

import java.util.Iterator;
import java.util.LinkedList;

public class LeetCode649 {
    public String predictPartyVictory(String senate) {
        LinkedList<Character> list = new LinkedList<Character>();

        char[] ch = senate.toCharArray();
        for(char c : ch){
            list.add(c);
        }
        int r = 0;
        int d = 0;
        while (list.size()>1&&list.stream().distinct().count()>1){
            Iterator<Character> it = list.iterator();
            while (it.hasNext()){
                char c = it.next();
                if(c == 'R' && d>0){
                    it.remove();
                    d -= 1;
                }else if(c == 'R' && d==0){
                    r += 1;
                }else if(c == 'D' && r>0){
                    it.remove();
                    r -= 1;
                }else if(c == 'D' && r==0){
                    d += 1;
                }
            }


        }

        if(list.getFirst() == 'R'){
            return "Radiant";
        }else {
            return "Dire";
        }

    }
}
